#include<iostream>
#include<vector>
using namespace std;
class Solution {
public:
    int minOperations(vector<int>& nums, int x) {
        int n = nums.size(), left = 0, right = 0, sum = 0, tog = 0;
        for (int i = 0; i < n; i++)
        {
            sum += nums[i];
        }
        int target = sum - x, flag = -1, MAX = 0;
        if (target < 0) return -1;
        while (right < n)
        {
            if (tog < target) tog += nums[right++];
            else if (tog > target) tog -= nums[left++];
            if(tog==target) 
            {
                flag = 1;
                MAX = max(MAX, right - left);
                tog += nums[right++];
            }
        }
        if (flag == -1)
            return flag;
        return n - MAX;
    }
};


int main()
{
    vector<int> v = { 5,2,3,1,1 };
    Solution s;
    cout<<s.minOperations(v, 5);
    return 0;
}